#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

int main(int argc,char** argv)
{
  int fd[2];
  int ret;
  ret = pipe(fd);
  if(ret < 0)
  {
    fprintf(stderr,"pipe is fail\n");
    return -1;
  }
  pid_t pid;
  pid = fork();
  if(pid < 0)
  {
    fprintf(stderr, "fork is fail\n");
    return -1;
  }

  if(pid > 0)
  {
    close(fd[0]);
    write(fd[1],"123456\n",7);
    close(fd[1]);
    wait(NULL);
  }

  if(pid == 0)
  {
    char buf[1024];
    int ret;
    close(fd[1]);
    ret = read(fd[0],buf,sizeof(buf));
    write(STDOUT_FILENO,buf,ret);
  }
  return 0;
}
